<?php
class ns_dao
{
    public $DB = null;
    
    public static function create() 
    {
        $d = new ns_dao();
        $d->Connect();
        return $d;
    }
    
    public function __construct()
    {
        $this->DB = new Database(); // becasuse we have already store the login details in the database lass we don't have to do anything here
        
    }

    public function __destruct()
    {   
        $this->Disconnect(); // make sure the database connection hase been droped
        unset($this->DB);
    }
    
    public function Connect()
    {
        $this->DB->connect();
    }
    
    private function Disconnect()
    {
        $this->DB->disconnect();
    }
        
    public function query($sql,$key_column = null)
    {
        $this->Connect();        
        $result = $this->DB->query($sql,$key_column);
        $this->Disconnect();
        return $result;
    }

    public function update($sql)
    {
        $this->Connect();
        $rowCount = $this->DB->update($sql);
        $this->Disconnect();
        return $rowCount;
    }


}
?>